'''
作业
'''


# 1.
def func1(fn):
    def test(*args, **kwargs):
        fn(*args, **kwargs)
        print('after')

    return test


@func1
def func2():
    print('before')


func2()


# 2.
def func3(fn):
    def test(*args, **kwargs):
        re = fn(*args, **kwargs) + 100
        return re

    return test


@func3
def func4(x):
    x += 20
    return x


print(func4(100))


# 3.
def tag(fn):
    def test(*args, **kwargs):
        text = fn(*args, **kwargs)
        return '<p>' + text + '</p>'

    return test


@tag
def render(text):
    # 执行其他操作
    return text


@tag
def render2():
    return 'abc'


print(render('hello'))
print(render2())


# 4.


def tag(name):
    def wrapper(fn):
        def test(*args, **kwargs):
            if name == 'p':
                text = fn(*args, **kwargs)
                return '<p>' + text + '</p>'
            elif name == 'div':
                text = fn(*args, **kwargs)
                return '<div>' + text + '</div>'

        return test

    return wrapper


@tag(name='p')
def render(text):
    # 执行其他操作
    return text


print(render('hello'))


@tag(name='div')
def render2():
    return 'abc'


print(render2())


# 5.


def func7(flag):
    def wrapper(fn):
        def test(*args, **kwargs):
            if flag:
                re = fn(*args, **kwargs)
                return re + 100
            else:
                re = fn(*args, **kwargs)
                return re - 100

        return test

    return wrapper


f = False


@func7(f)
def func8(n):
    return n


print(func8(100))
